package no.mehdi.usereg.web.action;

import no.mehdi.usereg.rfid.controllers.RFIDController;
import no.mehdi.usereg.web.form.RfidForm;

import org.springframework.webflow.action.MultiAction;

public class RfidAction extends MultiAction{
	
	private RfidThread thread;
	private RfidForm form;
	private RFIDController rfidController;
	
	public void start() throws Exception {
		
		if (thread == null) {
			thread = new RfidThread(rfidController);
			//thread.setDaemon(true);
			thread.run();
			form.setEnabled(true);
		}
	}

	public void stop() throws Exception {
		if (thread != null) {
			try {

				thread.stopRfid();
				
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}finally{
				thread = null;
				System.gc();
			}
		}
		form.setEnabled(false);
	}

	public void setUuid(String uuid) {
		form.setUuid(uuid);
		
	}

	public void fireListener() {
		form.fireListener();
	}

	public void setForm(RfidForm form) {
		this.form = form;
	}

	public void setRfidController(RFIDController rfidController) {
		this.rfidController = rfidController;
	}

	public RFIDController getRfidController() {
		return rfidController;
	}

}
